package com.wcs.exam.controller.auth;

import com.wcs.exam.common.base.Result;
import com.wcs.exam.common.base.page.Page;
import com.wcs.exam.controller.auth.biz.AuthOrderInfoBiz;
import com.wcs.exam.controller.auth.req.*;
import com.wcs.exam.controller.auth.resp.AuthOrderInfoGoodsResp;
import com.wcs.exam.controller.auth.resp.AuthOrderInfoPageResp;
import com.wcs.exam.controller.auth.resp.AuthOrderInfoPayResp;
import com.wcs.exam.controller.auth.resp.AuthOrderInfoResultResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * Auth-订单信息表
 *
 * @author wcs
 * @since 2025-03-26
 */
@Tag(name = "Auth-订单相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/auth/order")
public class AuthOrderController {

    @NotNull
    private final AuthOrderInfoBiz biz;

    @Operation(summary = "下单接口")
    @PostMapping(value = "/pay")
    public Result<AuthOrderInfoPayResp> pay(@RequestBody @Valid AuthOrderInfoPayReq req) {
        return biz.pay(req);
    }

    @Operation(summary = "用户中心-订单继续支付")
    @PostMapping(value = "/continue/pay")
    public Result<AuthOrderInfoPayResp> continuePay(@RequestBody @Valid AuthOrderInfoContinuePayReq req) {
        return biz.continuePay(req);
    }

    @Operation(summary = "用户中心-取消订单")
    @PutMapping(value = "/cancel")
    public Result<String> cancel(@RequestBody @Valid AuthOrderInfoCancelReq req) {
        return biz.cancel(req);
    }

    @Operation(summary = "订单信息查看")
    @GetMapping(value = "/view")
    public Result<AuthOrderInfoGoodsResp> view(@ModelAttribute @Valid AuthOrderInfoGoodsReq req) {
        return biz.view(req);
    }

    @Operation(summary = "订单信息查看-支付结果查询")
    @Parameter(name = "tradeSerialNo", description = "交易流水号", required = true)
    @GetMapping(value = "/result")
    public Result<AuthOrderInfoResultResp> result(@RequestParam Long tradeSerialNo) {
        return biz.result(tradeSerialNo);
    }

    @Operation(summary = "用户中心-订单分页")
    @GetMapping(value = "/page")
    public Result<Page<AuthOrderInfoPageResp>> page(@ModelAttribute AuthOrderInfoPageReq req) {
        return biz.page(req);
    }
}
